package projectsupporter.common.operation;

import jxl.Hyperlink;
import jxl.Sheet;
import jxl.Workbook;

import org.eclipse.swt.widgets.Shell;

import projectsupporter.common.formbase.progrees.LongRunningOperation;
import projectsupporter.form.MainForm;
import dbTools.DBToolEngine;

public class LoadTableInfoOperation2 extends LongRunningOperation{

	private DBToolEngine engine; 
	
	private MainForm form;
	
	public LoadTableInfoOperation2(MainForm form,Shell shell, String fileName) {
		super(shell);
		this.form=form;
		engine=new DBToolEngine(fileName);
		progressBar.open();
		setActionName("Loding Tanle Info...");
	}
	
	public void run()
	{
	Workbook workbook = engine.getWorkBook();
		
		System.out.println("共有" +workbook.getNumberOfSheets() + "sheets");
		
		Sheet mainSheet = workbook.getSheet("テーブル一覧");
		
		if(mainSheet==null){
			return ;
		}
	   Hyperlink[] tableLinks =mainSheet.getHyperlinks();
		
	   setMax(tableLinks.length);
		
	    int index=1;
		for(Hyperlink link:tableLinks)
		{
			move(index++,engine.fillTableInfo(workbook, mainSheet, link));
		}
		
	    if(DBToolEngine.TABLE_INFO_MAP!=null)
	    {
	    	form.getsShell().getDisplay().asyncExec(new Runnable() {
				public void run() {
					progressBar.close();
					form.fillTableTree(DBToolEngine.TABLE_INFO_MAP);
					
				}
			});
	    }
	}
}
